import sys
sys.path.append('F:\sundries\test\python\analyse')
import numpy as np
import sdf_helper as sh

data = sh.getdata('10012.sdf')
var = data.Electric_Field_Ey
shape = var.data.shape
# ========================================
# find the maximum std
max_ey = 0
max_ey_num = 0
nx = 650
ny = 2400
x = int(23 / 50.0 * nx)
y = int(36 / 50.0 * nx)
yx = int((-5 + 15) / 30 * ny)
yy = int((5 + 15) / 30 * ny)
E_invalid = 10
for i in range(x, y):
    print(i)
    temp = var.data[i][yx:yy].flatten()
    temp = np.abs(temp)
    print('original len:%d' % len(temp))
    k = 0
    for j in range(len(temp)):  #该循环剔除电场强度小于某一给定值E_invalid
        if temp[k] < E_invalid:
            temp = np.delete(temp, k)
        else:
            k += 1
    print('operated len:%d' % len(temp))
    temp_val = np.percentile(temp, 99)
    if max_ey < temp_val:
        max_ey = temp_val
        max_ey_num = i
print('max_ey is', max_ey, 'in x=', max_ey_num)
#====================================================
temp = var.data[max_ey_num]
print('x[max_ey_num].mean=', temp.mean())
print('x[max_std_num].percentile.99=', temp.std())
#===================================================
